// ----------------------------------------------------------------------------
// gfx_device_osx.cpp
// ----------------------------------------------------------------------------
#include "../gfx.h" // TODO : MOVE IT.
#include "gfx_device_osx.h"

namespace fw
{
    GfxDeviceInternal::GfxDeviceInternal(const GfxDeviceConfig& config)
    : m_mouselb(0)
    , m_mousemb(0)
    , m_mouserb(0)
    , m_mousex (0)
    , m_mousey (0)
    {
        uint32_t marginX = 64, marginY=64;
        GfxOpenWindow(marginX, marginY, config.GetWidth(), config.GetHeight());
    }
    
    GfxDeviceInternal::~GfxDeviceInternal()
    {
    }
    
    bool GfxDeviceInternal::PollDevice()
    {
        GfxPollDevice();
        GfxMouseEvent(m_mouselb, m_mousemb, m_mouserb, m_mousex, m_mousey);
        
        int wid, hei, cx, cy;
        GfxGetWindowSize(wid, hei);
        cx=wid/2;
		cy=hei/2;
        
		glViewport(0,0,wid,hei);
        
        return true;
    }
    
    bool GfxDeviceInternal::Flip()
    {
        glFlush();
        
        GfxSwapBuffer();
        
        int passedTime = GfxPassedTime();
        int interval   = 17;
		GfxSleep(interval-passedTime);
        
        return true;
    }
    
} // namespace fw

